using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Inventory.Domain.Models;

namespace Inventory.Database.Mapping
{
    public class MovieMap : EntityTypeConfiguration<Movie>
    {
        public MovieMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            // Table & Column Mappings
            this.ToTable("Movies");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.IMDbId).HasColumnName("IMDbId");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.MovieRatingId).HasColumnName("MovieRatingId");
            this.Property(t => t.Runtime).HasColumnName("Runtime");
            this.Property(t => t.SynopsisLong).HasColumnName("SynopsisLong");
            this.Property(t => t.SynopsisShort).HasColumnName("SynopsisShort");
            this.Property(t => t.PlotOutline).HasColumnName("PlotOutline");
            this.Property(t => t.Comments).HasColumnName("Comments");
            this.Property(t => t.InternetUrl).HasColumnName("InternetUrl");
            this.Property(t => t.UserRating).HasColumnName("UserRating");
            this.Property(t => t.MyRating).HasColumnName("MyRating");
            this.Property(t => t.ReleaseYear).HasColumnName("ReleaseYear");
            this.Property(t => t.Poster).HasColumnName("Poster");
            this.Property(t => t.PosterThumb).HasColumnName("PosterThumb");

            // Relationships
            this.HasOptional(t => t.MovieRating)
                .WithMany(t => t.Movies)
                .HasForeignKey(d => d.MovieRatingId);

        }
    }
}
